package com.xhcl.web.controller.system;



import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.TSrhsZfpzti;
import com.xhcl.system.domain.TSrhsZfpzto;
import com.xhcl.system.service.ITGgDlyhwhService;
import com.xhcl.system.service.ITSrhsZfpztiService;
import com.xhcl.system.service.ITSrhsZfpztoService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.common.core.page.TableDataInfo;
import com.xhcl.framework.shiro.util.ShiroUtils;

/**
 * 国库支付凭证头Controller
 * 
 * @author xhcl
 * @date 2020-09-09
 */
@Controller
@RequestMapping("/system/zfpzto")
public class TSrhsZfpztoController extends BaseController
{
    private String prefix = "system/zfpzto";

    @Autowired
    private ITSrhsZfpztoService tSrhsZfpztoService;
    @Autowired
    private ITSrhsZfpztiService tSrhsZfpztiService;
    @Autowired
    private ITGgDlyhwhService tGgDlyhwhService;

    @RequiresPermissions("system:zfpzto:view")
    @GetMapping()
    public String zfpzto(ModelMap mmap)
    {
    	mmap.put("yhlist",tGgDlyhwhService.selectTGgDlyhwhList(null));
        return prefix + "/zfpzto";
    }

    /**
     * 查询国库支付凭证头列表
     */
    @RequiresPermissions("system:zfpzto:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSrhsZfpzto tSrhsZfpzto)
    {
        startPage();
        List<TSrhsZfpzto> list = tSrhsZfpztoService.selectTSrhsZfpztoList(tSrhsZfpzto);
        return getDataTable(list);
    }

    /**
     * 导出国库支付凭证头列表
     */
    @RequiresPermissions("system:zfpzto:export")
    @Log(title = "国库支付凭证头", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSrhsZfpzto tSrhsZfpzto)
    {
        List<TSrhsZfpzto> list = tSrhsZfpztoService.selectTSrhsZfpztoList(tSrhsZfpzto);
        ExcelUtil<TSrhsZfpzto> util = new ExcelUtil<TSrhsZfpzto>(TSrhsZfpzto.class);
        return util.exportExcel(list, "zfpzto");
    }

    /**
     * 新增国库支付凭证头
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存国库支付凭证头
     */
    @RequiresPermissions("system:zfpzto:add")
    @Log(title = "国库支付凭证头", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TSrhsZfpzto tSrhsZfpzto)
    {   String operName = ShiroUtils.getSysUser().getLoginName();
        return toAjax(tSrhsZfpztoService.insertTSrhsZfpzto(tSrhsZfpzto,operName));
    }

    /**
     * 修改国库支付凭证头
     */
    @GetMapping("/edit/{zfxh}")
    public String edit(@PathVariable("zfxh") Long zfxh, ModelMap mmap)
    {
        TSrhsZfpzto tSrhsZfpzto = tSrhsZfpztoService.selectTSrhsZfpztoById(zfxh);
        TSrhsZfpzti tSrhsZfpzti=new TSrhsZfpzti();
        tSrhsZfpzti.setZfxh(zfxh);
        List<TSrhsZfpzti> tSrhsZfpztiList = tSrhsZfpztiService.selectTSrhsZfpztiList(tSrhsZfpzti);
        mmap.put("tSrhsZfpzto", tSrhsZfpzto);
        mmap.put("tSrhsZfpztiList", tSrhsZfpztiList);
        return prefix + "/edit";
    }

    /**
     * 修改保存国库支付凭证头
     */
    @RequiresPermissions("system:zfpzto:edit")
    @Log(title = "国库支付凭证头", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TSrhsZfpzto tSrhsZfpzto)
    {   
    	String operName = ShiroUtils.getSysUser().getLoginName();
        return toAjax(tSrhsZfpztoService.updateTSrhsZfpzto(tSrhsZfpzto,operName));
    }

    /**
     * 删除国库支付凭证头
     */
    @RequiresPermissions("system:zfpzto:remove")
    @Log(title = "国库支付凭证头", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tSrhsZfpztoService.deleteTSrhsZfpztoByIds(ids));
    }
    
    
    /**
     * 删除国库支付凭证头
     */
    @RequiresPermissions("system:zfpzto:verify")
    @Log(title = "审核国库支付凭证", businessType = BusinessType.DELETE)
    @PostMapping( "/verify")
    @ResponseBody
    public AjaxResult verify(String ids)
    {   String operName = ShiroUtils.getSysUser().getLoginName();
    	tSrhsZfpztoService.verifyTsrhsZfpztoByIds(ids, operName);
        return AjaxResult.success();
    }
    @RequiresPermissions("system:zfpzto:cancel")
    @Log(title = "撤销支付凭证", businessType = BusinessType.UPDATE)
    @PostMapping("/cancel")
    @ResponseBody
    public AjaxResult cancel(TSrhsZfpzto tSrhsZfpzto)
    {   
    	tSrhsZfpztoService.ZfpzCancel(tSrhsZfpzto);
        return AjaxResult.success();
    }
}
